/**
 * 资产变动js
 */

$(function () {
	initialPage();
	getGrid();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {height: $(window).height()-56});
	});
}

function getGrid() {
	$('#dataGrid').bootstrapTableEx({
		url: '../../sys/bank/change?_' + $.now(),
		height: $(window).height()-56,
		queryParams: function(params){
			params.name = vm.keyword;
			return params;
		},
		columns: [
			// {checkbox: true},
            {field : "typeName", title : "资产类型", width : "100px"},
            {field : "normalNum", title : "正常数量", width : "100px"},
            {field : "badNum", title : "损坏数量", width : "100px"},
            {field : "totalNum", title : "总数", width : "100px"},
            {title : "损坏率", width : "100px",formatter:function (value, row, index) {
                if (isNaN(row.badNum) || isNaN(row.totalNum)) {
                    return "-";
                }
                return row.totalNum <= 0 ? "0%" : (Math.round(row.badNum / row.totalNum * 10000) / 100.00)+"%";
                }},
            {title : "正常率", width : "100px",formatter:function (value, row, index) {
                    if (isNaN(row.normalNum) || isNaN(row.totalNum)) {
                        return "-";
                    }
                    return row.totalNum <= 0 ? "0%" : (Math.round(row.normalNum / row.totalNum * 10000) / 100.00)+"%";
                }},
		]
	})
}

var vm = new Vue({
	el:'#dpLTE',
	data: {
		keyword: null
	},
	methods : {
		load: function() {
			$('#dataGrid').bootstrapTable('refresh');
		},
		save: function() {
			dialogOpen({
				title: '新增资产信息',
				url: 'base/capital/add.html?_' + $.now(),
				width: '420px',
				height: '350px',
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		edit: function(id) {
            dialogOpen({
                title: '编辑资产信息',
                url: 'base/capital/edit.html?_' + $.now(),
                width: '420px',
                height: '350px',
                success: function(iframeId){
                    top.frames[iframeId].vm.bank.id = id;
                    top.frames[iframeId].vm.setForm();
                },
                yes: function(iframeId){
                    top.frames[iframeId].vm.acceptClick();
                }
            });
        },
        remove: function(batch, id) {
            var ids = [];
            if (batch) {
                var ck = $('#dataGrid').bootstrapTable('getSelections');
                if (!checkedArray(ck)) {
                    return false;
                }
                $.each(ck, function(idx, item){
                    ids[idx] = item.id;
                });
            } else {
                ids.push(id);
            }
            $.RemoveForm({
                url: '../../sys/bank/remove?_' + $.now(),
                param: ids,
                success: function(data) {
                    vm.load();
                }
            });
        }
	}
})